<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 联想小鑫
  Date: 2021/11/15
  Time: 19:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <link rel="stylesheet" href="css/img.css">
</head>
<body>
<form action="list.do" method="post"></form>
<table border="1">
    <tr>
        <td></td>
        <td>编号</td>
        <td>商品名称</td>
        <td>商品编号</td>
        <td>商品品牌</td>
        <td>规格型号</td>
        <td>价格</td>
        <td>上架时间</td>
        <td>图片</td>
        <td>
            <button id="addy">添加</button>
        </td>
    </tr>
    <c:forEach var="s" items="${list}">
        <tr>
            <td>
                <input type="checkbox" value="${s.sid}">
            </td>
            <td>${s.sid}</td>
            <td>${s.sname}</td>
            <td>${s.card}</td>
            <td>${s.brandName}</td>
            <td>${s.sstyle}</td>
            <td>${s.sprice}</td>
            <td>${s.stime}</td>
            <td>
                <img src="${s.pic}" alt="该图片无法展示" width="75px">
            </td>
            <td>
                <button class="xg" value="${s.sid}">修改</button>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="10">
            一共${page.getTotal()}条记录
            第${page.getPageNum()}页/共${page.getPages()}页
            <button onclick="go(1)">首页</button>
            <button onclick="go(${page.getPageNum()}-1)">上一页</button>
            <button onclick="go(${page.getPageNum()}+1)">下一页</button>
            <button onclick="go(${page.getPages()})">尾页</button>
        </td>
    </tr>
    <tr>
        <td>
            <button id="qx">全选</button>
            <button id="qbx">全不选</button>
            <button id="fx">反选</button>
            <button id="ps">批量删除</button>
        </td>
    </tr>
</table>
</body>
<script>
    function go(pageNum) {
        location="list.do?pageNum="+pageNum+"&"+$("form").serialize();
    }
    $("#qx").click(function () {
        $(":checkbox").attr("checked",true);
    })
    $("#qbx").click(function () {
        $(":checkbox").attr("checked",false);
    })
    $("#fx").click(function () {
        $(":checkbox").each(function () {
            $(this).attr("checked",!$(this).attr("checked"));
        })

    })
    $("#ps").click(function () {
        var id="";
        $(":checkbox:checked").each(function () {
            id+=","+$(this).val();
        })
        id=id.substring(1);
        if(id!=null){
            if(confirm("你确认删除编号为"+id+"的编号信息吗?")){
                $.ajax({
                    url:"delids.do",
                    data:{"id":id},
                    dataType:"json",
                    type:"post",
                    success:function (a) {
                        if(a>0){
                            alert("删除成功");
                            location="list.do";
                        }
                    }
                })
            }
        }else{
            alert("请至少选择一个编号进行删除");
        }
    })
    $("#addy").click(function () {
        location="addy.do";
    })
    $(".xg").click(function () {
        location="updy.do?id="+$(this).val();
    })
</script>
</html>
